package com.atguigu.shargingjdbcdemo.mapper;

import com.atguigu.shargingjdbcdemo.entity.Order;
import com.atguigu.shargingjdbcdemo.entity.OrderVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {

    @Select({
        "SELECT " +
            "o.order_no, " +
            "SUM(i.price * i.count) AS amount",
        "FROM t_order o JOIN t_order_item i ON o.order_no = i.order_no",
        "GROUP BY o.order_no"
    })
    List<OrderVo> getOrderAmount();


/**
 * 这里不支持跨库查询
  */
//    @Select({"SELECT " +
//                 "u.id AS userId,",
//                 "u.uname,",
//                 "o.id AS orderId,",
//                 "o.order_no,",
//                 "o.amount",
//             "FROM t_user u " +
//             "LEFT JOIN t_order o ON o.user_id = u.id"})
//    List<UserOrderVo> findJoin();

}
